package com.itheima.mp.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.itheima.mp.entity.User;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MateObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Object createdTime = getFieldValByName("createdTime", metaObject);

        if(createdTime == null){
            setFieldValByName("createdTime", LocalDateTime.now(),metaObject);
        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
